* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    background: #f5f5f5;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 280px;
    background: #202123;
    color: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #444;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #444;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #656669 0%, #717177 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.new-chat-btn:hover {
    transform: scale(1.02);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 12px;
    margin-bottom: 4px;
    background: #2a2b2e;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    border: 2px solid transparent;
}

.history-item:hover {
    background: #3a3b3e;
}

.history-item.active {
    background: #3a3b3e;
    border-color: #6c6e79;
}

.history-item-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.history-item-date {
    font-size: 12px;
    color: #8e8e8e;
}

.history-item-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.history-item-btn {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.2s;
}

.history-item-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.history-item-btn.delete {
    background: rgba(220, 53, 69, 0.3);
}

.history-item-btn.delete:hover {
    background: rgba(220, 53, 69, 0.5);
}

/* 主聊天区域 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-header {
    background: linear-gradient(135deg, #5f6063 0%, #5b585e 100%);
    color: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-header h1 {
    font-size: 20px;
    font-weight: 600;
}

.thread-id {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 4px;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
    font-weight: 500;
}

.btn-clear {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-clear:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f5f5f5;
}

.message {
    margin-bottom: 8px;
    display: flex;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
}

/* 头像样式 */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex: 0 0 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    user-select: none;
}

.avatar.ai {
    background: linear-gradient(135deg, #667eea 0%, #5e5c5f 100%);
    margin-right: 8px;
}

.avatar.user {
    background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
    margin-left: 8px;
}

.message {
    align-items: flex-start;
    gap: 0;
}
.message-content {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.user .message-content {
    background: linear-gradient(135deg, #272727 0%, #4a4a4d 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.message.tool .message-content {
    background: transparent;
    color: #333;
    padding: 0;
}

.tool-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    color: #495057;
    font-size: 12px;
    line-height: 1.4;
    cursor: default;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.tool-btn:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    border-color: #667eea;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.15);
}

.tool-btn::before {
    content: "🔧";
    font-size: 14px;
}

/* Markdown 样式 */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: 16px;
    margin-bottom: 8px;
    font-weight: 600;
    line-height: 1.25;
}

.message-content h1 { font-size: 1.8em; }
.message-content h2 { font-size: 1.5em; }
.message-content h3 { font-size: 1.3em; }

.message-content p {
    margin-bottom: 12px;
}

.message-content ul,
.message-content ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content code {
    background: #f6f8fa;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.message-content pre {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    position: relative;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    color: #e6e6e6;
    font-size: 0.9em;
    line-height: 1.5;
}

.message-content blockquote {
    border-left: 4px solid #667eea;
    padding-left: 16px;
    margin: 12px 0;
    color: #666;
    font-style: italic;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
}

.message-content table th,
.message-content table td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.message-content table th {
    background: #f6f8fa;
    font-weight: 600;
}

.message-content a {
    color: #667eea;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content hr {
    border: none;
    border-top: 2px solid #e0e0e0;
    margin: 16px 0;
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 12px 0;
}

/* 代码复制按钮 */
.code-block-wrapper {
    position: relative;
}

.copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s;
}

.copy-button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.copy-button.copied {
    background: #4caf50;
}

.chat-input-container {
    padding: 20px 24px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.chat-input-form {
    display: flex;
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
}

.chat-input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
    resize: none;
    min-height: 52px;
    max-height: 150px;
    font-family: inherit;
}

.chat-input:focus {
    border-color: #667eea;
}

.btn-send {
    padding: 14px 28px;
    background: linear-gradient(135deg, #387ec4 0%, #4b4be0 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.2s;
    height: fit-content;
    align-self: flex-end;
}

.btn-send:hover {
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* 用户消息中的代码样式 */
.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message.user .message-content pre {
    background: rgba(0, 0, 0, 0.3);
}

/* 空状态 */
.empty-state {
    text-align: center;
    color: #999;
    padding: 40px 20px;
    font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        width: 220px;
    }

    .message-content {
        max-width: 85%;
    }
}